import request from '../utils/request'

/*根据分类id获取参数*/
export function getAttributesByCateId(id,params){
  return request({
    method:'get',
    url:`categories/${id}/attributes`,
    params
  })
}

/*根据分类id和属性id获取参数*/
export function getOneAttribute(cateId,attrId){
  return request({
    method:'get',
    url:`categories/${cateId}/attributes/${attrId}`
  })
}


/*添加参数 
data = {
  attr_name:string
  attr_sel:string, ['only'|'many']
}
*/
export function addAttribute(id,data){
  return request({
    method:'post',
    url:`categories/${id}/attributes`,
    data
  })
}

/*删除参数*/
export function deleteAttribute(cateId,attrId){
  return request({
    method:'delete',
    url:`categories/${cateId}/attributes/${attrId}`
  })
}

/*修改参数 
  data={
    attr_name:String
    attr_sel:string, ['only'|'many']
    attr_vals:String, 'value1 value2' (可选)
  }
*/
export function updateAttribute(cateId,attrId,data){
  return request({
    method:'put',
    url:`categories/${cateId}/attributes/${attrId}`,
    data
  })
}